﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

try { document.execCommand("BackgroundImageCache", false, true); } catch (e) { }
var popUpWin;
function PopUpCenterWindow(URLStr, width, height, newWin, scrollbars) {
    var popUpWin = 0;
    if (typeof (newWin) == "undefined") {
        newWin = false;
    }
    if (typeof (scrollbars) == "undefined") {
        scrollbars = 0;
    }
    if (typeof (width) == "undefined") {
        width = 800;
    }
    if (typeof (height) == "undefined") {
        height = 600;
    }
    var left = 0;
    var top = 0;
    if (screen.width >= width) {
        left = Math.floor((screen.width - width) / 2);
    }
    if (screen.height >= height) {
        top = Math.floor((screen.height - height) / 2);
    }
    if (newWin) {
        open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
        return;
    }

    if (popUpWin) {
        if (!popUpWin.closed) popUpWin.close();
    }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scrollbars + ',resizable=yes,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
    popUpWin.focus();
}

function OpenModelWindow(url, option) {
    var fun;
    try {
        if (parent != null && parent.$ != null && parent.$.ShowIfrmDailog != undefined) {
            fun = parent.$.ShowIfrmDailog
        }
        else {
            fun = $.ShowIfrmDailog;
        }
    }
    catch (e) {
        fun = $.ShowIfrmDailog;
    }
    fun(url, option);
}
function CloseModelWindow(callback, dooptioncallback) {
    parent.$.closeIfrm(callback, dooptioncallback);
}


function StrFormat(temp, dataarry) {
    return temp.replace(/\{([\d]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { if (s instanceof (Date)) { return s.getTimezoneOffset() } else { return encodeURIComponent(s) } } else { return "" } });
}
function StrFormatNoEncode(temp, dataarry) {
    return temp.replace(/\{([\d]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { if (s instanceof (Date)) { return s.getTimezoneOffset() } else { return (s); } } else { return ""; } });
}
function getiev() {
    var userAgent = window.navigator.userAgent.toLowerCase();
    $.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
    $.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
    $.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
    var v;
    if ($.browser.msie8) {
        v = 8;
    }
    else if ($.browser.msie7) {
        v = 7;
    }
    else if ($.browser.msie6) {
        v = 6;
    }
    else { v = -1; }
    return v;
}
$(document).ready(function() {
    var v = getiev()
    if (v > 0) {
        $(document.body).addClass("ie ie" + v);
    }

});
function   DateAdd(interval,number,date)
{
/*
  *---------------   DateAdd(interval,number,date)   -----------------
  *   DateAdd(interval,number,date)  
  *   功能:实现VBScript的DateAdd功能.
  *   参数:interval,字符串表达式，表示要添加的时间间隔.
  *   参数:number,数值表达式，表示要添加的时间间隔的个数.
  *   参数:date,时间对象.
  *   返回:新的时间对象.
  *   var   now   =   new   Date();
  *   var   newDate   =   DateAdd( "d ",5,now);
  *   author:wanghr100(灰豆宝宝.net)
  *   update:2004-5-28   11:46
  *---------------   DateAdd(interval,number,date)   -----------------
  */
        switch(interval)
        {
                case   "y "   :   {
                        date.setFullYear(date.getFullYear()+number);
                        return   date;
                        break;
                }
                case   "q "   :   {
                        date.setMonth(date.getMonth()+number*3);
                        return   date;
                        break;
                }
                case   "m "   :   {
                        date.setMonth(date.getMonth()+number);
                        return   date;
                        break;
                }
                case   "w "   :   {
                        date.setDate(date.getDate()+number*7);
                        return   date;
                        break;
                }
                case   "d "   :   {
                        date.setDate(date.getDate()+number);
                        return   date;
                        break;
                }
                case   "h "   :   {
                        date.setHours(date.getHours()+number);
                        return   date;
                        break;
                }
                case   "M "   :   {
                        date.setMinutes(date.getMinutes()+number);
                        return   date;
                        break;
                }
                case   "s "   :   {
                        date.setSeconds(date.getSeconds()+number);
                        return   date;
                        break;
                }
                default   :   {
                        date.setDate(d.getDate()+number);
                        return   date;
                        break;
                }
        }
}
function checkEx(now, end) {
    if (now.getYear() == end.getYear() && now.getMonth() == end.getMonth() && now.getDay() == end.getDay()) {
        return true;
    }
    if (now.getDay() == 0  && end < DateAdd("d ",-7,now)){
        return false;
    }
    if (now.getDay() == 6 && end < DateAdd("d ",-6,now)){
        return false;
    }
//    if ((end.getDay() == 0 || end.getDay() == 6) && end < now-2) {
//        return false;
//    }
    var oneDayTime = 1000 * 60 * 60 * 24;
    var now_count = parseInt(now.getTime() / oneDayTime);
    var end_other = parseInt(end.getTime() / oneDayTime);
    return parseInt((now_count + 4) / 7) == parseInt((end_other + 4) / 7);
}


/************+
validate the date formate, which is used as client validation function
************/
function validateDateText(sender, args) {
    var text = args.Value;
    if (text) {
        var parts = text.split('-');
        var day = parseInt(parts[2]);
        var month = parseInt(parts[1]);
        var year = parseInt(parts[0]);
        if (Array.contains([1, 3, 5, 7, 8, 10, 12], month) && day > 31) {
            args.IsValid = false;
        }
        else if (Array.contains([4, 6, 9, 11], month) && day > 30) {
            args.IsValid = false;
        }
        else if (month == 2) {
            // non-leap year
            if (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)) {
                args.IsValid = day <= 28;
            }
            else {
                args.IsValid = day <= 29;
            }
        }
    }
}
function validateTimeText(sender, args) {
    var text = args.Value;
    if (text) {
        var parts = text.split(':');
        var hour = parseInt(parts[0]);
        var minute = parseInt(parts[1]);
        var second = 0;
        if (parts.length > 2) {
            second = parseInt(parts[2]);
        }
        if (hour > 23) {
            args.IsValid = false;
        } else if (minute > 59) {
            args.IsValid = false;
        } else if (second > 59) {
            args.IsValid = false;
        }
    }
}
function validateIntegerText(sender, args) {
    args.IsValid = args.Value.isInteger();
}
function validatePhoneNumberText(sender, args) {
    args.IsValid = args.Value.isPhoneNumber();
}


function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function daysElapsed(date1, date2) {
    var difference =
        Date.UTC(y2k(date1.getYear()), date1.getMonth(), date1.getDate(), 0, 0, 0)
      - Date.UTC(y2k(date2.getYear()), date2.getMonth(), date2.getDate(), 0, 0, 0);
    return difference / 1000 / 60 / 60 / 24;
}


